package com.gnerv.battle.boot.module.base.config;

import com.gnerv.battle.boot.common.base.constants.DatabaseProductName;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author Gnerv LiGen
 */
@Configuration
@MapperScan("com.gnerv.battle.boot.module.base.repository.mapper")
public class BattleBaseMybatisConfig {

    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties properties = new Properties();
        properties.put(DatabaseProductName.POSTGRESQL, DatabaseProductName.POSTGRESQL.toLowerCase());
        properties.put(DatabaseProductName.MYSQL, DatabaseProductName.MYSQL.toLowerCase());
        properties.put(DatabaseProductName.ORACLE, DatabaseProductName.ORACLE.toLowerCase());
        databaseIdProvider.setProperties(properties);
        return databaseIdProvider;
    }

}
